package com.zhang.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.domain.Permissions;
import com.zhang.domain.Role;
import com.zhang.mapper.PermissionMapper;
import com.zhang.mapper.RoleMapper;
import com.zhang.query.RoleQuery;
import com.zhang.service.IPermissionService;
import com.zhang.service.IRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zh
 * @create 2022-02-14 9:25
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class PermissionServiceImpl implements IPermissionService {
    @Resource
    private PermissionMapper mapper;

    @Override
    public List<Permissions> findPermission() {
        return mapper.findPermission();
    }

    @Override
    public List<Integer> findMyPermission(Long roleId) {
        List<Integer> list = new ArrayList<>();
        for (Long aLong : mapper.findMyPermission(roleId)) {
            list.add(Integer.valueOf(aLong.toString()));
        }
        return list;
    }
    @Transactional
    @Override
    public void addRp(Long roleId,Long[] permissionIds){
        mapper.deleteRp(roleId);
        if(permissionIds!=null&&permissionIds.length>0){
            mapper.addRp(roleId,permissionIds);
        }
    }

    @Override
    public Long findRoIdById(Long id) {
        return mapper.queryByEmpId(id);
    }
}
